package org.protege.owl.examples.tab;

import java.util.*;

import javax.swing.JTextArea;


/**
 * @author Szymon Janikowski
 *
 */
public class InstanceSet
{
	private Predicate predicate;
	private List<String> col1;
	private List<String> col2;
	
	public InstanceSet(Predicate pred)
	{
		predicate = pred;
		col1 = new ArrayList<String>();
		if (pred.argumentsNmb()==2)
			col2 = new ArrayList<String>();
		else 
			col2 = null;
	}
	
	
	public List<String> getColumn(int column) throws InappropriateInstanceSetUsage
	{
		if (column == 1) return col1;
		if (column == 2) 
			if (predicate.argumentsNmb()==2)
				return col2;
			else
				throw new InappropriateInstanceSetUsage();
		else return null;
	}
	
	public void add(int column, String newInstance) throws InappropriateInstanceSetUsage
	{
		if (column==1)
			col1.add(newInstance);
		if (column==2)
			if (predicate.argumentsNmb()==2)
				col2.add(newInstance);
			else
				throw new InappropriateInstanceSetUsage();
	}
	

	public void add(String newInstance) throws InappropriateInstanceSetUsage
	{
		if (predicate.argumentsNmb()==1)
			col1.add(newInstance);
		else
			throw new InappropriateInstanceSetUsage();
	}
	
	public void add(String newInstance1, String newInstance2) throws InappropriateInstanceSetUsage
	{
		if(predicate.argumentsNmb() == 2)
		{
			col1.add(newInstance1);
			col2.add(newInstance2);
		}
		else
			throw new InappropriateInstanceSetUsage();	
	}
	
	private void listRow(int index,JTextArea textarea)
	{
		if (predicate.argumentsNmb()==1)
			textarea.setText(textarea.getText() + col1.get(index) + "\n");
		else if (predicate.argumentsNmb()==2)
			textarea.setText(textarea.getText() + col1.get(index) + "\t" + col2.get(index) + "\n");
	}
	
	public void listSet(JTextArea textarea)
	{
		for (int i=0;i<col1.size();i++)
			listRow(i,textarea);
	}


	public int size()
	{
		return col1.size();
	}
	
	
	
}
